//
//  GameInfo.cpp
//  test
//
//  Created by songxiao on 13-12-25.

#include "GameInfo.h"
#include "battleCry.pb.h"
#include "log.h"

using namespace BattleCry;

int getAutoMatchFormation(int exp, SEL_CallFunc_GetFormation selector, CCObject* target)
{
    GameInfo* pGameInfo = new GameInfo(target, selector);
    pGameInfo->getGameInfo(63364695);
}

void GameInfo::getGameInfo(unsigned int uid)
{
    CCTcpRequestShort* pRequest = new CCTcpRequestShort();
    pRequest->setIp("192.168.1.147");
    pRequest->setPort(12346);
    pRequest->setCmd(2);
    pRequest->setSelector(callfuncND_selector(GameInfo::getGameInfoCallback));
    pRequest->setUid(uid);
    pRequest->setTarget(this);
    string sData = "battle cry, send message";
    pRequest->setData(sData.c_str());
    
    CCTcpClientShort::getInstance()->send(pRequest);
    pRequest->release();
}

void GameInfo::getGameInfoCallback(CCNode* pNode, void* pData)
{
    CCTcpReponseShort* pReponse = (CCTcpReponseShort*)pData;

    ForMationInfo temp;
    if(temp.ParseFromString(*(pReponse->getData())))
    {
        
        if(_pObject && _pSeletor)
            (_pObject->*_pSeletor)((unsigned char*)temp.sdata().c_str(), temp.sdata().length());
        CCLOG("get data size: %lu", temp.sdata().length());
    }
    
    
}